const app = getApp()
//console.log(wx.getUserInfo())



Page({
  data:{
  },
  onLoad:function(option){

    var that = this
    var user=wx.getStorageSync('user') || {};
    var userInfo=wx.getStorageSync('userInfo') || {};
    //wx.setStorageSync('user',null)
    console.log("init.onLoad")

    
    
    if(!user.openid) {
      
      wx.login({
        success: function (res) {
          //this.getOpenId(res);
       
        },
        fail:function(e){
          wx.showModal({
            title:e+""
          })
        },
        complete:function(res){
          
          var d = app.globalData;//这里存储了appid、secret、token串
          //var l = 'https://apis.weixin.qq.com/sns/jscode2session?appid=' + d.appid + '&secret=' + d.secret + '&js_code=' + res.code + '&grant_type=authorization_code';
          var l = app.globalData.urlGlobal+'/commonZwl/huoquOpenid/?code=' + res.code;
          wx.request({
            url: l,
            data: {},
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            complete: function (res) {
              // wx.showModal({
              //   title:JSON.stringify(res)+""
              // })
              let obj={}
              obj.openid = res.data.openid;
              wx.setStorageSync('user', obj);//存储openid
              // wx.showModal({
              //   title:obj.openid+""
              // })
              console.log(obj);
              wx.navigateTo({
                url:'/pages/index/index'
              })
      

      
            }
          });

          
          
        }
      });
    }else{
      // wx.showModal({
      //   title:user.openid+""
      // })
      wx.navigateTo({
        url:'/pages/index/index'
      })
    }

  },

})